
<div class="mainbar" id="contentPost">
	<div class="article">
          <h2><span>Advance search</span></h2>
          <div class="clr"></div>
          <div class="bg-custom col-md-11 col-md-offset-1" align=right>
          <form id="formSearchAdvance" role="form" action="/search/doAdvanceSearch" method="get">
			  <div class="form-group">
			    <label class="control-label col-sm-3" for="title">Title of the blog</label>
			    <div class="col-xs-7">
			    	<input name="title" type="text" class="form-control" id="title" placeholder="Enter blog title" value="<?php if(isset($_GET['title'])) echo $_GET['title'];?>" autofocus>
			    </div>
			  </div>
			  <div class="clr"></div>
			  <div class="form-group" style="margin-top: 10px">
			    <label class="control-label col-sm-3" for="postuser">Posted by user</label>
			    <div class="col-xs-7">
			    	<input name="postuser" type="text" class="form-control" id="postuser" placeholder="Enter user posted" value="<?php if(isset($_GET['postuser'])) echo $_GET['postuser'];?>">
			    </div>
			  </div>
			  <div class="clr"></div>
<!-- 			  <br/> -->
			  <div class="form-group" style="margin-top: 10px">
			    <label class="control-label col-sm-3" for="datecreatefrom">Date create from</label>
			    <div style="float: left; padding: 0 15px 0 15px;" class="input-group date form_date col-xs-7" data-date="" data-date-format="yyyy/mm/dd" data-link-field="dtp_input1" data-link-format="yyyy/mm/dd">
                    <input name="datecreatefrom" class="form-control" type="text" value="<?php if(isset($_GET['datecreatefrom'])) echo $_GET['datecreatefrom'];?>" readonly>
					<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
				<input type="hidden" id="dtp_input1" value="" />
			  </div>
			  <div class="clr"></div>
			  <div class="form-group" style="margin-top: 10px">
			    <label class="control-label col-sm-3" for="datecreateto">Date create to</label>
			    <div style="float: left; padding: 0 15px 0 15px;" class="input-group date form_date col-xs-7" data-date="" data-date-format="yyyy/mm/dd" data-link-field="dtp_input1" data-link-format="yyyy/mm/dd">
                    <input name="datecreateto" class="form-control" type="text" value="<?php if(isset($_GET['datecreateto'])) echo $_GET['datecreateto'];?>" readonly>
					<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
				<input type="hidden" id="dtp_input1" value="" />
			  </div>
			  <div class="clr"></div>
			  <br/>
			  <div class="form-group">
				  <label class="control-label col-sm-3" for="btnLogin"></label>
				  <div class="col-xs-6">
				    	<button type="submit" class="btn btn-primary col-xs-7">Search</button>
				  </div>
		  	  
		  	  </div>
		  </form>
		  </div>
        </div>
        <div class="clr"></div>
        <br><br>
        
        <script type="text/javascript" src="/js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
		<script type="text/javascript">
		    $('.form_datetime').datetimepicker({
		        //language:  'fr',
		        weekStart: 1,
		        todayBtn:  1,
				autoclose: 1,
				todayHighlight: 1,
				startView: 2,
				forceParse: 0,
		        showMeridian: 1
		    });
			$('.form_date').datetimepicker({
		//          language:  'en',
		        weekStart: 1,
		        todayBtn:  1,
				autoclose: 1,
				todayHighlight: 1,
				startView: 2,
				minView: 2,
				forceParse: 0,
		 		format: 'yyyy/mm/dd'
		    });
			$('.form_time').datetimepicker({
		        language:  'fr',
		        weekStart: 1,
		        todayBtn:  1,
				autoclose: 1,
				todayHighlight: 1,
				startView: 1,
				minView: 0,
				maxView: 1,
				forceParse: 0
		    });
		</script>
        
<?php
if (isset ( $posts )) {
	foreach ( $posts as $post ) :
		?>
	<div class="article">
		<h2>
			<a class="linkTitle"
				href="/posts/detail/<?php echo $post['Post']['id']; ?>"><span><?php echo $post['Post']['title']; ?></span></a>
		</h2>
		<div class="clr"></div>
		<p class="infopost">
			<span class="date"><?php echo $post['Post']['created']; ?></span> <span>&nbsp;&bull;&nbsp;</span>
			Posted by <a
				href="/adminposts/profile/<?php echo $post['Post']['user_id']; ?>"><?php echo $post['Post']['username']; ?></a>
			&nbsp;|&nbsp;
			<!-- Filed under <a href="#">templates</a>, <a href="#">internet</a> -->
			with <a
				href="/posts/detail/<?php echo $post['Post']['id']; ?>#commentListID"
				class="com"><?php echo $post['Post']['numComment']?> Comments</a>
		</p>
		<img src="<?php echo $post['Post']['thumbnail']; ?>" width="201"
			height="146" alt="" class="fl" />

		<div align="justify"><?php echo $post['Post']['body']; ?></div>

		<div class="clr"></div>
		<p class="spec" align="right">
			<a href="/posts/detail/<?php echo $post['Post']['id']; ?>" class="rm">Read
				more &raquo;</a>
		</p>
	</div>
<?php
	
endforeach
	;
}
?>
<div id="loading">Loading data...</div>
</div>
<!-- Sidebar -->
<div class="sidebar">
      <?php
						
if (isset ( $sidebarList )) {
							echo $this->element ( 'sidebar', array (
									"sidebarList" => $sidebarList 
							) );
						}
						?>
				</div>
<!-- end Sidebar -->
<div class="clr"></div>
<script>
/*
 * ThanhLD1 - script load more data
 * This function using ajax to load more data if user scroll at bottom screen
 */
$(function(){
    var $start=10;
    var $window=$(window);
    var $loading=$('#loading');
    var $status=true;
    $window.on( 'scroll',function(eS){

    	//if not load more data (not have more data) don't load more data again
    	if($(this).scrollTop() /( $(document).height() - $(this).height()) >=0.99){
    		$status=false;	
       	}

    	//load more data when user scroll to new bottom
        if($(this).scrollTop() /( $(document).height() - $(this).height()) > 0.95 && $status ){
            $.ajax({
               type:'post',
               url:'/search/getmoreAdvanceSearch',
               dataType:'html', 
               data:{start: $start},
               beforeSend:function(){
                  $status=false;
                  $loading.show();   
               },
               success:function(data){
                    if(data){
                        $('#contentPost').append(data);
                    }else{
                        $window.off(eS);
                    }
               },
               complete:function(){
                    $status=true;
                    $loading.fadeOut();
                    $start+=10; 
               },
               error:function(){
					$status=false;
               }
            });                
        }
    });
});
</script>